home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / ToolServer Examples / Userstartup•ToolServer < prev   
Encoding:
Text File  |  1998-12-03  |  5.9 KB  |  144 lines  |  [TEXT/MPS ]

  1. #    UserStartup•ToolServer
  2. #
  3. #    Copyright Apple Computer, Inc. 1991
  4. #    All Rights Reserved.
  5. #
  6. #        by Peter Canning and Brian Strull
  7. #        (with lots of help from Mitch Adler)
  8. #
  9.  
  10. #    This file defines some menu items and aliases for making ToolServer easier
  11. #    to use from the MPW Shell.  This is a startup file for the MPW Shell, and
  12. #    should be moved to either your MPW directory or into the MPW preferences
  13. #    folder.  This file is not required for running ToolServer, but illustrates
  14. #    some techniques for using ToolServer from the MPW Shell.
  15.  
  16. #    This file sets up and defines an alias ToolServerExecute for sending
  17. #    commands to a ToolServer in a very similar way to how commands are sent
  18. #    to MPW Shell.
  19.  
  20. #    ToolServerExecute needs MPW Shell version 3.3a8 or later, and ToolServer
  21. #    version 1.0a4 or later.
  22.  
  23. #    ToolServerExecute works similarly to pressing the ENTER key, but sends the
  24. #    commands to a ToolServer process running on some machine on the network.
  25. #
  26. #    If the selection is empty, the entire line containing the selection is
  27. #    sent to ToolServer and a newline is appended to the end of the line,
  28. #    otherwise (if the selection is non-empty), the selection is sent to
  29. #    ToolServer.  In both cases the text is evaluated by ToolServer not
  30. #    by MPW Shell.  This means that the ToolServer default directory, aliases,
  31. #    variable settings (especially "{Commands}") will affect the behaviour of
  32. #    the evaluation.
  33. #
  34. #    The disposition of the results (standard output, and standard error) of the
  35. #    commands sent to ToolServer are controlled by a number of factors.
  36. #    First, the rules of rshell and ToolServer are followed (see the
  37. #    ToolServer documentation about redirection).  By default, script output from
  38. #   ToolServer will be returned to the MPW Shell where it will be processed by 
  39. #     ToolServerExecute as  specified by the MPW Shell variable ToolServerRedirection.  
  40. #    If ToolServerRedirection is not set, the output will be appended to the end
  41. #    of the {Active} window (this, unfortunately, is slightly different than what
  42. #    happens when you press the ENTER key in MPW Shell).  You are advised to redirect
  43. #    ToolServer output into another window, so that the MPW Shell and ToolServer
  44. #    output does not get mixed up (and so you don't get mixed up either).
  45.  
  46. #    The following variables can be used to configure the behavior of
  47. #    ToolServerExecute:
  48.  
  49. #    The variable WhichToolServer controls what process to send commands to.
  50. #    It should be set to one of the options that controls rshell:
  51. #        -b                                 background (ToolServer on the local machine)
  52. #        -f                                 foreground (MPW Shell on the local machine)
  53. #        -r Zone:Machine:Application        some other ToolServer or MPW Shell
  54. #
  55. #    If the variable is not set, the PPC browser is used.
  56.  
  57. Set WhichToolServer '-b'    # ToolServer on local machine
  58. export WhichToolServer
  59.  
  60. #    The variable ToolServerRedirection controls the disposition of output
  61. #    from ToolServer.  We suggest directing standard output and diagnostic
  62. #    output to another window.
  63.  
  64. set ToolServerWindow       "{MPW}WorkSheet•TS"
  65. set ToolServerRedirection "∑∑ ∂'{ToolServerWindow}∂'"    # Append output (and error) to the end of "{MPW}WorkSheet•TS"
  66. export ToolServerRedirection
  67.  
  68. #    Create a ToolServer menu.
  69. #
  70. #    YOU MUST CONNECT ToolServerExecute TO A MENU ENTRY OR KEY.
  71. #    Since it acts on the selection in the {Active} window, you can't 
  72. #    type it as an MPW Shell command and press ENTER.
  73. #
  74. #    The following binds ToolServerExecute to Command-\ (Command-Backslash).
  75.  
  76. addmenu ToolServer 'Execute Selection/\' ToolServerExecute
  77.  
  78. #    Set Environment will copy your shell variables, aliases, exports, and 
  79. #     current directory from the MPW Shell to ToolServer.  You can use this
  80. #     menu item for synchronizing your environment.
  81.  
  82. addmenu ToolServer 'Set Environment' 'UpdateToolServerEnv'
  83.  
  84. #     Open Output opens a window in the MPW Shell on the file containing your
  85. #    ToolServer output.  We first try to open it for read/write, and if that
  86. #    fails, we open it read-only.
  87.  
  88. addmenu ToolServer 'Open Output'      'begin; open -n "{ToolServerWindow}" || open -r "{ToolServerWindow}"; end ∑∑ "dev:null"'
  89. addmenu ToolServer '(-' ''
  90.  
  91. #     Quit ToolServer sends a quit message to the ToolServer.
  92.  
  93. addmenu ToolServer 'Quit ToolServer' 'rshell -q {WhichToolServer}'
  94.  
  95.  
  96. #     Build Menu Additions
  97. #
  98. #    This is a simple addition to the build menu to run the build in the background.
  99. #
  100. AddMenu Build '(-' ''
  101. AddMenu Build 'Background Build…' ∂
  102.     'Begin; ∂
  103.      Set NewProgram "`Request "Program Name?" -d "{Program}" || Echo '""'`"; ∂
  104.      Exit If "{NewProgram}" == ""; ∂
  105.      Set Program "{NewProgram}"; ∂
  106.      rshell "begin; directory `directory`; Echo; Echo; BuildProgram ∂"{Program}∂"; end;" {WhichToolServer}{ToolServerRedirection};∂
  107.      End >> "{Worksheet}" ≥≥ Dev:StdOut'
  108.  
  109.  
  110. #    I would suggest creating a script that contains aliases, and variable
  111. #    settings that you use frequently as well as setting the initial state of
  112. #    MPW Shell and ToolServer and then executing that script from both your
  113. #    UserStartup•≈ file and UserStartupTS•≈ file, so that commands, scripts and
  114. #    aliases will work consistently in both environments.  You may also use
  115. #    the Set Environment menu item as well.
  116.  
  117.  
  118. #    Finally here is the ToolServerExecute command itself.  
  119.  
  120. set ToolServerStarted 0
  121.  
  122. alias 'ToolServerExecute'  ∂
  123.     'if "{Active}" != "{ToolServerWindow}"; open -n -t "{ToolServerWindow}"; end; ∂
  124.      if `count -c "{Active}".§` == 0; ∂
  125.         find !0 "{Active}"; ∂
  126.         rshell < "{Active}".§ {WhichToolServer} {ToolServerRedirection}; ∂
  127.         replace §Δ ∂n "{Active}"; ∂
  128.      else; ∂
  129.         rshell < "{Active}".§ {WhichToolServer} {ToolServerRedirection}; ∂
  130.      end; ∂
  131.      set ToolServerStarted 1'
  132.  
  133.  
  134. #
  135. #    Here is an enhancement (contributed by Warren Harris) that sets
  136. #    ToolServer's default directory to the same thing as MPW Shell's before
  137. #    executing the selected command.  You might want to bind this  alias to
  138. #    a key instead of ToolServerExecute.
  139. #
  140. alias 'ToolServerExecute•dir' ∂
  141.     'set dir `directory`; ∂
  142.      rshell "directory ∂"{dir}∂"" {WhichToolServer} ∑ dev:null; ∂
  143.      ToolServerExecute'
  144.